package main.collection;

import java.util.*;

/**
 * Created by ChengGM on 2016/12/19.
 */
public class CompareTest {



    public static void main(String args[]) {
        List<Compare> list = new ArrayList<Compare>();
        for (int i = 1; i < 8; i++) {
            Compare co = new Compare();
            co.setAge(i + 2);
            list.add(co);
        }

        Collections.sort(list, new Comparator<Compare>() {
            @Override
            public int compare(Compare o1, Compare o2) {
                if (o1.getAge() > o2.getAge()) {
                    return -1;
                }
                if (o1.getAge() < o2.getAge()) {
                    return 1;
                }
                return 0;
            }
        });
        for(Compare co : list){
        System.out.print(co.getAge()+"   ");
        }

    }
}

class  Compare {
    int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}

